package com.example.test.model;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;

import org.json.JSONObject;

public class CommonFunc {

	public static BufferedReader createBufferedReader(String path)
	{
		try {
			return new BufferedReader(new InputStreamReader(new FileInputStream(path)));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static PrintWriter createPrintWriter(String path)
	{
		try {
			return new PrintWriter(new OutputStreamWriter(new FileOutputStream(path)));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String FromSinaDateToStamp(String sDate)
	{
		SimpleDateFormat dateFormat =new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy",new Locale("en"));
		try {
			
			Date date=dateFormat.parse(sDate);
			
			return date.getTime()+"";
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String FromSinaDateTo(String sDate,String pattern)
	{
		SimpleDateFormat dateFormat =new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy",new Locale("en"));
		try {
			
			Date date=dateFormat.parse(sDate);
			dateFormat.applyPattern(pattern);
			String formatStr = dateFormat.format(date);
			return formatStr;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String translateSinaSource(String source)
	{
		int sIndex=source.indexOf(">");
		int eIndex=source.indexOf("</a>");
		return source.substring(sIndex+1,eIndex);
	}
	
}
